<?php
require_once('cls_sqlite.php');
$DB=new SQLite('db/todo.db');
$type=$_GET["t"];
switch ($type) {
    case 'setok':
        setok();
        break;
    case 'list':
        getlist();
        break;  
    case 'add':
        addtodo();
        break; 
    case 'del':
        deltodo();
        break;    
    
    default:
        // code...
        break;
}
function getlist()
{
    $data=$GLOBALS["DB"]->getlist('select * from todolist order by id');
    $retdata=json_encode($data);
    echo $retdata;
    
}
function addtodo()
{
    $sql="insert into todolist(title,deadline,isok) values('".$_POST["title"]."','".$_POST["date"]."',0)";
    $data=$GLOBALS["DB"]->query($sql);
    if($data)
    {
         echo 1;
    }else{
         echo 0;
    }
}
function deltodo()
{
    $sql="delete from todolist where id=".$_GET["id"]."";
    $data=$GLOBALS["DB"]->query($sql);
    if($data)
    {
         echo 1;
    }else{
         echo 0;
    }
}

function setok()
{
    $sql="update todolist set isok=1 where id=".$_GET["id"]."";
    $data=$GLOBALS["DB"]->query($sql);
    if($data)
    {
         echo 1;
    }else{
         echo 0;
    }
}